package com.gitee.hermer.engine.jars.dependent.disconf.configuration;

import java.io.IOException;
import java.util.Map;

import javax.sql.DataSource;

import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportAware;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.annotation.Order;
import org.springframework.core.type.AnnotationMetadata;

import com.baidu.disconf.client.DisconfMgrBean;
import com.baidu.disconf.client.DisconfMgrBeanSecond;
import com.gitee.hermer.boot.jee.commons.bean.utils.BeanLocator;
import com.gitee.hermer.boot.jee.commons.collection.CollectionUtils;
import com.gitee.hermer.boot.jee.commons.log.UtilsContext;
import com.gitee.hermer.engine.jars.core.domain.EngineConstant;
import com.gitee.hermer.engine.jars.dependent.disconf.annotate.EnableDisconfScan;
import com.gitee.hermer.engine.jars.dependent.disconf.config.DisconfClientProperties;
import com.gitee.hermer.engine.jars.dependent.dsm.IEnginePropertiesAware;



@Configuration
public class DisconfClientAutoConfiguration extends UtilsContext implements Ordered{
	
	
	
	@Bean(destroyMethod = "destroy",initMethod="init")
	@Order(HIGHEST_PRECEDENCE)
	public DisconfMgrBeanSecond disconfMgrBeanSecond() {
		return new DisconfMgrBeanSecond();
	}
	
	@Bean
	public DisconfClientProperties disconfClientProperties(){
		return new DisconfClientProperties();
	}
	
	@Bean(destroyMethod = "destroy",name=EngineConstant.SPRING_BEAN_NAME_DISCONF_MGRBEAN)
	@Autowired
	public DisconfMgrBean disconfMgrBean(DisconfClientProperties properties,ApplicationContext applicationContext) throws IOException {
		BeanLocator.setSpringContext(applicationContext);
		DisconfMgrBean bean = new DisconfMgrBean();
		bean.setScanPackage(properties.getScanPackage());
		return bean;
	}
	
	
	@Override
	public int getOrder() {
		return HIGHEST_PRECEDENCE+200;
	}

	
}
